﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WiTeach.ClassManagement.DAL;
using WiTeach.CourseManagement.DAL;
using WiTeach.CourseManagement.View;
using WiTeach.MaterialManagement.DAL;
using WiTeach.MaterialManagement.Model;

namespace WiTeach.MaterialManagement.View
{
    /// <summary>
    /// MaterialList.xaml 的交互逻辑
    /// </summary>
    public partial class MaterialList : Page
    {
        private static int pageNow = 0;
        private static int pageSize = 8;
        public string class_name;

        public MaterialList(int lessonID, int classHourID)
        {
            InitializeComponent();
            // 修改页面背景主题
            ImageBrush brush = new ImageBrush();
            brush.Stretch = Stretch.Fill;
            brush.ImageSource = new BitmapImage(new Uri(App.backgroundImage, UriKind.RelativeOrAbsolute));
            this.Background = brush;
            List<Material> materialList = MaterialDAL.getMerterialListByClassID(lessonID, classHourID);
            this.materialList.ItemsSource = materialList;
        }

        public MaterialList(string className)
        {
            InitializeComponent();



            //class_name = className;
            ////获取标题
            //this.classNameLabel.Content = class_name;

            ////this.classNameLabel.Content = CourseDAL.getCourseNameByID(LessionID).ToString();

            ////分页
            //int totalCount = MaterialDAL.getMaterialCount();
            //int pageCount = (totalCount + pageSize - 1) / pageSize;
            //if (totalCount >= 8)
            //{
            //    this.prePageArrow.Visibility = System.Windows.Visibility.Visible;
            //    this.nextPageArrow.Visibility = System.Windows.Visibility.Visible;
            //}
            //initMaterialList(MaterialDAL.getCurrentPagingList(0, pageSize, pageCount));
            ////initMaterialList(MaterialDAL.getCurrentPagingList(0, pageSize, pageCount));
        }

        //#region 课时按钮操作相关内容
        ///// <summary>
        ///// 遍历数据集合内容，控制控件隐藏和显示
        ///// </summary>
        ///// <param name="classList"> 数据集合</param>
        //public void initMaterialList(List<Material> materialList)
        //{
        //    string canvasName = "materialList_";
        //    for (int i = 0; i < materialList.Count; i++)
        //    {
        //        // 拼接字符串控制属性显示
        //        canvasName += (i + 1);
        //        switch (canvasName.ToString())
        //        {
        //            case "materialList_1":
        //                this.materialName_1.DataContext = materialList[i];
        //                this.materialImage_1.DataContext = materialList[i];
        //                this.materialNumName_1.DataContext = materialList[i];
        //                this.materialList_1.Visibility = System.Windows.Visibility.Visible;
        //                break;
        //            case "materialList_2":
        //                this.materialName_2.DataContext = materialList[i];
        //                this.materialImage_2.DataContext = materialList[i];
        //                this.materialNumName_2.DataContext = materialList[i];
        //                this.materialList_2.Visibility = System.Windows.Visibility.Visible;
        //                break;
        //            case "materialList_3":
        //                this.materialName_3.DataContext = materialList[i];
        //                this.materialImage_3.DataContext = materialList[i];
        //                this.materialNumName_3.DataContext = materialList[i];
        //                this.materialList_3.Visibility = System.Windows.Visibility.Visible;
        //                break;
        //            case "materialList_4":
        //                this.materialName_4.DataContext = materialList[i];
        //                this.materialImage_4.DataContext = materialList[i];
        //                this.materialNumName_4.DataContext = materialList[i];
        //                this.materialList_4.Visibility = System.Windows.Visibility.Visible;
        //                break;
        //            case "materialList_5":
        //                this.materialName_5.DataContext = materialList[i];
        //                this.materialImage_5.DataContext = materialList[i];
        //                this.materialNumName_5.DataContext = materialList[i];
        //                this.materialList_5.Visibility = System.Windows.Visibility.Visible;
        //                break;
        //            case "materialList_6":
        //                this.materialName_6.DataContext = materialList[i];
        //                this.materialImage_6.DataContext = materialList[i];
        //                this.materialNumName_6.DataContext = materialList[i];
        //                this.materialList_6.Visibility = System.Windows.Visibility.Visible;
        //                break;
        //            case "materialList_7":
        //                this.materialName_7.DataContext = materialList[i];
        //                this.materialImage_7.DataContext = materialList[i];
        //                this.materialNumName_7.DataContext = materialList[i];
        //                this.materialList_7.Visibility = System.Windows.Visibility.Visible;
        //                break;
        //            case "materialList_8":
        //                this.materialName_8.DataContext = materialList[i];
        //                this.materialImage_8.DataContext = materialList[i];
        //                this.materialNumName_8.DataContext = materialList[i];
        //                this.materialList_8.Visibility = System.Windows.Visibility.Visible;
        //                break;

        //        }

        //        canvasName = "materialList_";

        //    }
        //}
        //#endregion
        //#region 课时列表分页

        //private void prePage(object sender, RoutedEventArgs e)
        //{
        //    Button btn = (Button)sender;
        //    if (!btn.IsVisible)
        //        return;
        //    int totalCount = MaterialDAL.getMaterialCount();
        //    int pageCount = (totalCount + pageSize - 1) / pageSize;
        //    --pageNow;
        //    setMaterialCanvasVisibility();
        //    initMaterialList(MaterialDAL.getCurrentPagingList(pageNow, pageSize, pageCount));
        //}

        //private void nextPage(object sender, RoutedEventArgs e)
        //{
        //    Button btn = (Button)sender;
        //    if (!btn.IsVisible)
        //        return;
        //    int totalCount = MaterialDAL.getMaterialCount();
        //    int pageCount = (totalCount + pageSize - 1) / pageSize;
        //    ++pageNow;
        //    setMaterialCanvasVisibility();
        //    initMaterialList(MaterialDAL.getCurrentPagingList(pageNow, pageSize, pageCount));
        //}
        //#endregion
        ///// <summary>
        /// 隐藏按钮状态
        /// </summary>
        //public void setMaterialCanvasVisibility()
        //{
        //    this.materialList_1.Visibility = System.Windows.Visibility.Hidden;
        //    this.materialList_2.Visibility = System.Windows.Visibility.Hidden;
        //    this.materialList_3.Visibility = System.Windows.Visibility.Hidden;
        //    this.materialList_4.Visibility = System.Windows.Visibility.Hidden;
        //    this.materialList_5.Visibility = System.Windows.Visibility.Hidden;
        //    this.materialList_6.Visibility = System.Windows.Visibility.Hidden;
        //    this.materialList_7.Visibility = System.Windows.Visibility.Hidden;
        //    this.materialList_8.Visibility = System.Windows.Visibility.Hidden;
        //}

        private void backHomeButton_Click(object sender, RoutedEventArgs e)
        {
            NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/CourseManagement/View/CourseIndex.xaml", UriKind.Relative));
        }

        private void backPreLevel(object sender, RoutedEventArgs e)
        {
            this.NavigationService.GoBack();
            //NavigationService.GetNavigationService(this).Navigate(new Uri("/WiTeach;component/ClassManagement/View/ClassStudyIndex.xaml", UriKind.Relative));
        }
        private void materiallist_backmain_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void materiallist_backmain_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }
        private void materiallist_back_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void materiallist_back_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }
        private void materialist_pagearrow_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 61;
            image.Width = 34;
        }

        private void materialist_pagearrow_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 52;
            image.Width = 25;
        }
        private void course_keil_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 56;
            image.Width = 59;
        }
        private void course_keil_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 46;
            image.Width = 49;
        }
        private void course_arduino_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 54;
            image.Width = 60;
        }
        private void course_arduino_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void course_scratch_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 54;
            image.Width = 60;
        }
        private void course_scratch_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void course_flymcu_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 52;
            image.Width = 60;
        }
        private void course_flymcu_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void course_progisp_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 52;
            image.Width = 59;
        }
        private void course_progisp_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }
        private void course_s4a_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 53;
            image.Width = 59;
        }
        private void course_s4a_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 48;
            image.Width = 54;
        }

        private void uv4_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string KEIL_Lic_path = System.Configuration.ConfigurationManager.AppSettings["app_KEIL_Lic"];
                Process uv4 = new Process();
                uv4.StartInfo.FileName = KEIL_Lic_path;
                uv4.Start();
                uv4.WaitForExit();
                uv4.Close();
            }
            catch (Exception)
            {
            }

            //   System.Diagnostics.Process.Start(@KEIL_Lic_path);
        }

        private void progisp_Click(object sender, RoutedEventArgs e)
        {
            string progisp_path = System.Configuration.ConfigurationManager.AppSettings["app_progisp"];


            //     System.Diagnostics.Process.Start(@progisp_path);
            try
            {
                Process progisp = new Process();
                progisp.StartInfo.FileName = progisp_path;
                progisp.Start();
                progisp.WaitForExit();
                progisp.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void flymcu_Click(object sender, RoutedEventArgs e)
        {
            string flymcu_path = System.Configuration.ConfigurationManager.AppSettings["app_flymcu"];
            //          System.Diagnostics.Process.Start(@flymcu_path);
            try
            {
                Process flymcu = new Process();
                flymcu.StartInfo.FileName = flymcu_path;
                flymcu.Start();
                flymcu.WaitForExit();
                flymcu.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void arduino_Click(object sender, RoutedEventArgs e)
        {
            string arduino_path = System.Configuration.ConfigurationManager.AppSettings["app_arduino"];
            //        System.Diagnostics.Process.Start(@arduino_path);
            try
            {
                Process arduino = new Process();
                arduino.StartInfo.FileName = arduino_path;
                arduino.Start();
                arduino.WaitForExit();
                arduino.Close();
                GC.Collect();
            }
            catch (Exception)
            {
            }

        }

        private void sa_Click(object sender, RoutedEventArgs e)
        {
            string sa_path = System.Configuration.ConfigurationManager.AppSettings["app_s4a"];
            Process sa = new Process();
            try
            {
                sa.StartInfo.FileName = sa_path;
                Console.WriteLine("sa_path" + sa_path);
                sa.Start();
                sa.WaitForExit();
                sa.Close();
                GC.Collect();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }


        private void courselist_backmain_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void courselist_backmain_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }

        private void courselist_back_mouse_enter(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 66;
            image.Width = 104;
        }
        private void courselist_back_mouse_leave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            Image image = sender as Image;
            image.Height = 60;
            image.Width = 98;
        }


    }
}
